﻿#region Header
// ------------------------ Licence / Copyright ------------------------
// 
// ScrumTable for Scrum Meeting Support
// Copyright © HSR - Hochschule für Technik Rapperswil
// All Rights Reserved
// 
// Author:
//  Michael Gfeller Silvan Gehrig Patrick Boos
// 
// ---------------------------------------------------------------------
#endregion

#region Usings

using System.Collections.Generic;
using System.Data;
using ScrumTable.Common.Collections;

#endregion

namespace ScrumTable.Common.Data
{
    /// <summary>
    /// Provides the additional functionalities required for ADO.NET DataSet 
    /// management.
    /// </summary>
    public static class DataSetUtil
    {
        #region Properties
        //--------------------------------------------------------------------
        // Properties
        //--------------------------------------------------------------------

        #endregion

        #region Methods
        //--------------------------------------------------------------------
        // Methods
        //--------------------------------------------------------------------

        /// <summary>
        /// Returns the data table collection as a typed collection. 
        /// </summary>
        /// <param name="thisPtr">Specifies the DataSet pointer.</param>
        public static ICollection<DataTable> GetTables(this DataSet thisPtr)
        {
            PreCondition.AssertNotNull(thisPtr, "thisPtr");

            return thisPtr.Tables.Convert<DataTable>();
        }

        /// <summary>
        /// Make sures the data table with the given name and id exists
        /// inside the data set.
        /// </summary>
        /// <param name="thisPtr">Specifies the DataSet pointer.</param>
        /// <param name="name">Specifies the name of the table to search.</param>
        public static void EnsureDataTable(this DataSet thisPtr, string name)
        {
            PreCondition.AssertNotNull(thisPtr, "thisPtr");
            PreCondition.AssertNotNullOrEmpty(name, "name");

            if (!thisPtr.Tables.Contains(name))
            {
                thisPtr.Tables.Add(new DataTable(name));
            }
        }

        #endregion
    }
}